package controller.Menu;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import tools.FileManager;

import UI.menuBar.MenuFile;
import controller.IMainController;
import controller.IMenuController;

public class MenuFileController implements IMenuFileController{

	private MenuFile mView;
	private IMainController mMainController;
	private IMenuController mTopController;

	public MenuFileController(IMenuController top) {
		mTopController = top;
	}

	@Override
	public void setTopController(IMenuController cont) {
		this.mTopController = cont;
	}

	@Override
	public MenuFile getView() {
		return mView;
	}
	
	@Override
	public void setView(MenuFile view) {
		this.mView = view;
		this.mView.setController(this);
	}

	/**
	 * Open a File descriptor and load it into a TextEditor
	 * @param f
	 */
	@Override
	public void openFile(File f) {
		String res = FileManager.loadFile(f);
		mTopController.loadTextIntoTextEditor(res);
	}

	
	@Override
	public void saveFileAs(File f) {
		String text = mTopController.getTextOfTheBasicEditor();
		FileManager.writeFile(f, text);
	}
}
